template.helper('$parse', function(data) {
	return JSON.parse(data.replace(/\\\\/g, "\\"));
});
template.helper('$toArray', function(data) {
	var data = JSON.parse(data);
	var toArray = new Array();
	toArray = data.toString().split(",");
	return toArray;
});
template.helper('$toJson', function(data) {
	data = unescape(data.replace(/\u/g, "%u"));
	data = data.replace("[\"","");
	data = data.replace("\"]","");
	return data;
});
template.helper('pageParam', function(param) {
	switch (param) {
		case "totalpage":
			return MYPAGE.questionNum;
			break;
		case "pageno":
			return MYPAGE.pageno;
			break;
		case "testTitle":
			return MYPAGE.testTitle;
			break;
	}
});
template.helper('loadImage', function(data) {
//	alert(data);
	var pre = "<img src=\"" + MYAPP.webroot + "\/files\/";
	data = data.replace(/\[image\]/g, pre);
	data = data.replace(/\[\/image\]/g, '\">');
	data = data.replace(/src=\"\/files/g,"src=\"" + MYAPP.webroot + "\/files\/");
	return data;
});
template.helper('getDoingCount', function(data) {
	questionCount = 0 ;
	var db = new loki('data');
	db.loadDatabase({}, function() {
		var c = db.getCollection('answers');
		if (c == null) {
			c = db.addCollection('answers');
		}
//		alert(JSON.stringify(c.data));
		var q = {
			lesson:parseInt(data)
		};
		questionCount = c.find(q).length;		
	});
	return questionCount;
});